package com.ruoyi.eqmonitor.smdtv.controller;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAccessor;
import java.util.*;

import com.ruoyi.eqmonitor.smdtv.domain.SmdtvHydrologicStation;
import com.ruoyi.eqmonitor.smdtv.dtos.HydrologicStationDto;
import com.ruoyi.eqmonitor.smdtv.service.ISmdtvHydrologicStationService;
import com.ruoyi.eqmonitor.utils.HydrologicStationUtil;
import com.ruoyi.eqmonitor.utils.OpenApiUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;

import javax.servlet.http.HttpServletResponse;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.security.utils.SecurityUtils;

import com.ruoyi.common.core.web.page.TableDataInfo;

@Api(tags = "水文站")
@RestController
@RequestMapping("/station")
public class SmdtvHydrologicStationController extends BaseController{
    
    @Autowired
    private ISmdtvHydrologicStationService smdtvHydrologicStationService;

    /**
     * 查询水文站列表
     */
    @GetMapping("/list")
    public TableDataInfo<?> list(SmdtvHydrologicStation smdtvHydrologicStation){
        startPage();
        List<SmdtvHydrologicStation> list = smdtvHydrologicStationService.selectSmdtvHydrologicStationList(smdtvHydrologicStation);
        return getDataTable(list);
    }

    /**
     * 查询全部水文站
     */
    @GetMapping(value = "/all")
    public AjaxResult getAll(){
        return AjaxResult.success(smdtvHydrologicStationService.getAll());
    }

    /**
     * 根据id查询水文站
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id){
        return AjaxResult.success(smdtvHydrologicStationService.selectSmdtvHydrologicStationById(id));
    }

    /**
     * 新增水文站
     */
    @Log(title = "水文站", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SmdtvHydrologicStation smdtvHydrologicStation){
        return toAjax(smdtvHydrologicStationService.save(smdtvHydrologicStation));
    }

    /**
     * 修改水文站
     */
    @PutMapping
    public AjaxResult edit(@RequestBody SmdtvHydrologicStation smdtvHydrologicStation){
        return toAjax(smdtvHydrologicStationService.updateById(smdtvHydrologicStation));
    }

    /**
     * 传入@PathVariable的格式类似为/1,2,3,4,5时,会自动转为数组
     */
    @Log(title = "水文站", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids){
        return toAjax(smdtvHydrologicStationService.removeByIds(Arrays.asList(ids)));
    }
    
    /**
     * 导出水文站列表
     */
    @Log(title = "水文站", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SmdtvHydrologicStation smdtvHydrologicStation){
        List<SmdtvHydrologicStation> list = smdtvHydrologicStationService.selectSmdtvHydrologicStationList(smdtvHydrologicStation);
        ExcelUtil<SmdtvHydrologicStation> util = new ExcelUtil<SmdtvHydrologicStation>(SmdtvHydrologicStation.class);
        util.exportExcel(response, list, "水文站数据");
    }

    /**
     * 水位数据列表
     */
    @ApiOperation("水位数据列表")
    @PostMapping("/getDetail")
    public AjaxResult getDetail(@RequestBody HydrologicStationDto dto){
        return AjaxResult.success(smdtvHydrologicStationService.getDetail(dto));
    }

    /**
     * 导出水位数据列表
     */
    @Log(title = "导出水位数据列表", businessType = BusinessType.EXPORT)
    @PostMapping("/getDetail/export")
    public void detailExport(HttpServletResponse response, HydrologicStationDto dto){
        List<SmdtvHydrologicStation> list = smdtvHydrologicStationService.getDetail(dto);
        ExcelUtil<SmdtvHydrologicStation> util = new ExcelUtil<SmdtvHydrologicStation>(SmdtvHydrologicStation.class);
        util.exportExcel(response, list, "水位数据列表");
    }
    
}
